#include <stdio.h>
#include <malloc.h>
#include"..\Stack\zyf_Stack.h"
#define ERROR 2
#define OK 1
typedef int Status;
/*
	括号匹配
*/
Status matching(const char *c)
{
	for(int j = 0;j < 7; j++)
	{
		printf("%c\n",c[j]);
	}
	int i = 0;
	char k;
	SqStack S;

	Init_Stack(&S);

	while ( c[i] != '\0')
	{
		switch (c[i])
		{
			case '(':push(&S,c[i]);
				printf("---------------%d\n",0);
				break;
			case '[':push(&S,c[i]);
				printf("---------------%d\n",1);
				break;

			case '{':push(&S,c[i]);
				printf("---------------%d\n",2);
				break;

			case ')':pop(&S,&k);
				printf("---------------%d\n",k);
				if (k != '(')
				{
					printf("---------------%d\n",4);
					return ERROR;
				}
				break;
				
			case ']':pop(&S,&k);
				printf("---------------%c\n",k);
				if ('[' != k)
				{
					printf("---------------%d\n",6);
					return ERROR;
				}
				break;
			case '}':pop(&S,&k);
				printf("---------------%d\n",k);
				if ('{' != k)
				{
					printf("---------------%d\n",8);
					return ERROR;
				}
				break;

			default:
				break;
		}

		i++;
	}

	if (EmptyStack(&S) == 2)
	{
		printf("不为空\n");
		return ERROR;
	}
	else
	{
		return OK;
	}
}

int main(void)
{
	char c[7] = {'0'};
	
	c[0] = '{';
	c[1] = '1';
	c[2] = '(';
	c[3] = '[';
	c[4] = ']';
	c[5] = ')';
	c[6] = '}';
   	
	
	printf("检测括号匹配状态,状态码为：%d\n",matching(c));
}